package com.hyg.common.utils;

import android.content.Context;
import android.media.AudioManager;

import com.hyg.common.CommonLibary;

/**
 * FileName: AudioManagerUtil
 * Author: huangyuguang
 * Date: 2022/6/8
 * Description: 音量控制
 */
public class AudioManagerUtil {

    public static int getCurrentVol(int streamType){
        AudioManager mAudioManager = (AudioManager) CommonLibary.getContext().getSystemService(Context.AUDIO_SERVICE);
        int current = mAudioManager.getStreamVolume( streamType);
        return current;
    }

    public static void setRingVol(int vol){
        setVol(AudioManager.STREAM_RING, vol);
    }


    public static void setPlayVol(int vol){
        setVol(AudioManager.STREAM_MUSIC, vol);
    }

    private static void setVol(int streamType,int vol){
        AudioManager mAudioManager = (AudioManager)CommonLibary.getContext().getSystemService(Context.AUDIO_SERVICE);
        int max = mAudioManager.getStreamMaxVolume(streamType);
        if (vol > max){
            vol=max;
        }
        mAudioManager.setStreamVolume(streamType,vol, 0);
    }

    public static int getMaxVol(int streamType){
        AudioManager mAudioManager = (AudioManager)CommonLibary.getContext().getSystemService(Context.AUDIO_SERVICE);
        return mAudioManager.getStreamMaxVolume(streamType);
    }
}
